<?php
	class pdf extends common{
		var $config;
		var $user_id;
		
		function __construct($config,$user_id=''){
			$this->config = $config;
			$this->user_id = $user_id;
			parent::__construct();
		}
		
		/**
		 * 导出项目
		 * @param unknown $id
		 * @return unknown
		 */
		function createProject($id){
			$page = $this->config['domain'].'/project_info.php?a=pdf&id='.$id;
			$filename = $id.'.pdf';
			$create_path = $this->config['project_pdf_dir'].$filename;
			$file_path = $this->config['project_pdf_path'].$filename;
			
			if(!file_exists($create_path)) $r = $this->create($page,$create_path);
			return $file_path;
		}
		
		/**
		 * 导出电子票
		 * @param unknown $id
		 * @param unknown $ticket
		 * @return unknown
		 */
		function createTicket($id,$ticket){
			$page = $this->config['domain'].'/activity_ticket.php?a=pdf&id='.$id;
			$filename = $ticket.'.pdf';
			$create_path = $this->config['activity_pdf_dir'].$filename;
			$file_name = $this->config['activity_pdf_path'].$filename;
		
			if(!file_exists($create_path)) $r = $this->create($page,$create_path);
			return $file_name;
		}
		
		function create($url,$filename){
			$shell = $this->config['wkhtmltopdf_path']." --cookie user_id ".$this->user_id." '''$url''' ".$filename;
			exec($shell,$r);
		}
	}
?>